package com.common.demo.service;

import com.common.demo.entity.User;
import com.common.demo.entity.UserMaber;
import com.common.demo.entity.UserUtil;
import com.common.demo.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Description loginservice
 * @Author xiao  xun
 * @Date 2025-09-10
 */
@Service
public class loginservice implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user =userMapper.selectByUsername(username);
        if (user != null) {
            return new UserMaber( user);
        }
/* UserUtil userUtil = new UserUtil();
        BeanUtils.copyProperties(user,userUtil);
        if (user != null) {
            return  userUtil;
        }*/

        throw new UsernameNotFoundException("用户不存在");



    }
}
